package com.nowcoder.community.config;

import com.google.code.kaptcha.Producer;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * @ClassName KaptchaConfig
 * @Description
 * @Author hhwu
 * @Date 2022/5/19 11:23
 * Version 1.0
 **/
@Configuration// 声明配置类
public class KaptchaConfig {
    @Bean// 声明的bean将被spring管理，将方法交给spring时用@Bean，类的话用4个注解
    public Producer kaptchaProducer() {
        /**
         * @Author hhwu
         * @Description //TODO 配置验证码生成器
         * @Date 11:37 2022/5/19
         * @Param []
         * @return com.google.code.kaptcha.Producer
         **/
        Properties properties = new Properties();
        properties.setProperty("kaptcha.image.width", "100");
        properties.setProperty("kaptcha.image.height", "40");
        properties.setProperty("kaptcha.textproducer.font.size", "32");
        properties.setProperty("kaptcha.textproducer.font.color", "black");
        properties.setProperty("kaptcha.textproducer.char.string", "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ");
        properties.setProperty("kaptcha.textproducer.char.length", "4");
        properties.setProperty("kaptcha.noise.impl", "com.google.code.kaptcha.impl.NoNoise");
        

        DefaultKaptcha kaptcha = new DefaultKaptcha();
        Config config = new Config(properties);
        kaptcha.setConfig(config);
        return kaptcha;
    }
}
